<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :span="6"  >
            <a-form-item label="First Name" :labelCol="{ style: 'width: 100px' }" >
              <a-input placeholder="" v-model="queryParam.firstName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6"  >
            <a-form-item label="Last Name" :labelCol="{ style: 'width: 100px' }" >
              <a-input placeholder="" v-model="queryParam.lastName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="6"  >
            <a-form-item label="Status" :labelCol="{ style: 'width: 100px' }" >
              <j-dict-select-tag type="list" v-model="queryParam.payStatus"
                                 dictCode="payStatus"
                                 placeholder="" />
            </a-form-item>
          </a-col>
          <a-col :span="6" >
            <a-form-item label="Grade" :labelCol="{ style: 'width: 100px' }">
              <j-dict-select-tag type="list" v-model="queryParam.grade" dictCode="grade" placeholder="" style="width: 100%" />
            </a-form-item>
          </a-col>

         <!-- <a-col :xl="6" :lg="7" :md="6" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">Search</a-button>
              <a-button type="primary" @click="courseStudentSearchReset" icon="reload" style="margin-left: 8px">Reset</a-button>
            </span>
          </a-col>-->

        </a-row>
        <a-row  :gutter="24">

          <a-col :span="6" :offset="18" >
            <span style="float: right;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">Search</a-button>
              <a-button type="primary" @click="courseStudentSearchReset" icon="reload" style="margin-left: 8px">Reset</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">

      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>


      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
         <!-- <a @click="handleEdit(record)">Edit</a>

          <a-divider type="vertical" />-->
         <a-popconfirm title="Confirm to Delete??" ok-text="Yes" cancel-text="No" @confirm="() => handleDelete(record.id)">
                  <a >Delete</a>
         </a-popconfirm>
          <!--<a-dropdown>
            <a class="ant-dropdown-link">More <a-icon type="down" /></a>
            <a-menu slot="overlay">
            &lt;!&ndash;  <a-menu-item>
                <a @click="handleDetail(record)">Details</a>
              </a-menu-item>&ndash;&gt;
              <a-menu-item>
                <a-popconfirm title="Confirm to Delete??" ok-text="Yes" cancel-text="No" @confirm="() => handleDelete(record.id)">
                  <a>Delete</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

      </a-table>
    </div>

    <course-student-info-modal ref="modalForm" @ok="modalFormOk"></course-student-info-modal>
    <AddCourseStudentModal ref="addForm" :course-id="courseId" @ok="addFormOk"></AddCourseStudentModal>

  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import CourseStudentInfoModal from './modules/CourseStudentInfoModal'
  import AddCourseStudentModal from './modules/AddCourseStudentModal'

  export default {
    name: 'CourseStudentInfoList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      CourseStudentInfoModal,
      AddCourseStudentModal
    },
    props: {
      disabled: {
        type: Boolean,
        default: false,
        required: false
      },
      //课程ID
      courseId: {
        type:Number
      }
    },
    data () {
      return {
        description: 'CourseStudentInfoList',
        disableMixinCreated:true,
        // 表头
        columns: [
          /*{
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },*/
          {
            title:'ID',
            align:"center",
            width:100,
            dataIndex: 'id'
          },
          {
            title:'Chinese Name/WeChat Name',
            align:"center",
            width:180,
            dataIndex: 'chineseName'
          },
          {
            title:'First Name',
            align:"center",
            width:120,
            dataIndex: 'firstName'
          },
          {
            title:'Last Name',
            align:"center",
            width:120,
            dataIndex: 'lastName'
          },
          {
            title:'Phone',
            align:"center",
            width:120,
            dataIndex: 'phone'
          },
          {
            title:'School',
            align:"center",
            width:120,
            dataIndex: 'school'
          },
          {
            title:'Grade',
            align:"center",
            width:100,
            dataIndex: 'grade'
          },
          {
            title:'Status',
            align:"center",
            width:100,
            dataIndex: 'payStatus',
            customRender:(text,record,index) => {
              if(text === '2' || text === 2 ){
                return  <span>Paid</span>
              }else{
                return  <span>Reserved</span>
              }
            }
          },
          {
            title: '',
            dataIndex: 'action',
            align:"center",
            width:100,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/sistersophie/courseStudentInfo/list",
          delete: "/sistersophie/courseStudentInfo/delete",
          deleteBatch: "/sistersophie/courseStudentInfo/deleteBatch",
          exportXlsUrl: "/sistersophie/courseStudentInfo/exportXls",
          importExcelUrl: "sistersophie/courseStudentInfo/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.queryParam.courseId = this.courseId;
      this.loadData();
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      courseStudentSearchReset() {
        this.queryParam = {};
        this.queryParam.courseId = this.courseId;
        this.loadData(1);
      },
      handAddStudent(){
        this.$refs.addForm.add();
        this.$refs.addForm.title="Add Student";
        this.$refs.addForm.disableSubmit = false;
      },
      addFormOk() {
        // 新增/修改 成功时，重载列表
        this.loadData();
        //清空列表选中
        this.onClearSelected()
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'int',value:'courseId',text:'课程ID'})
        fieldList.push({type:'int',value:'studentId',text:'学生ID'})
        fieldList.push({type:'int',value:'studentStatus',text:'学生状态 0=正常入学，1=插班入学'})
        fieldList.push({type:'int',value:'payStatus',text:'付款状态 0=未付款，1=付款中，2=付款完成，3=付款失败,4=付款取消'})
        fieldList.push({type:'date',value:'payTime',text:'付款时间'})
        fieldList.push({type:'number',value:'price',text:'价格快照'})
        fieldList.push({type:'string',value:'description',text:'description'})
        fieldList.push({type:'int',value:'isDelete',text:'删除标志 0=未删除，1=已删除'})
        fieldList.push({type:'string',value:'createName',text:'创建人'})
        fieldList.push({type:'string',value:'updateName',text:'更新人'})
        fieldList.push({type:'int',value:'invoiceId',text:'通知ID'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>